<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Hits_Entity extends CI_Model
{
    private $tablename = 'hits';
    private $id = null;
    private $hits = null;
    private $sid = null;
    
    public function setId($Id)
    {
        $this->id = $Id;
    }

    public function setHits($Hits)
    {
        $this->hits = $Hits;
    }

    public function setSid($Sid)
    {
        $this->sid = $Sid;
    }

    public function save()
    {
        $params = array();
        foreach ($this as $key => $val) {
            if ($key == 'tablename') continue;
            if ($val == null || $val == '') continue;
            $params[$key] = $val;
        }
                
        if (!isset($params['id'])) {
            if ($this->db->insert($this->tablename, $params)) {
                return $this->db->insert_id();
            } else {
                return 0;
            }
        } else {
            return $this->db->update($this->tablename, $params, array('id' => $params['id']));
        }
        
    }
    
    public function del($id)
    {
        
        return $this->db->delete($this->tablename, array('id' => $id));    
    }
    
    public function getHitsById($id)
    {
        return $this->db->get_where($this->tablename, array('id' => $id));
    }
    
    public function getAllList()
    {
        return $this->db->get($this->tablename);
    }
    
    public function TotalHits()
    {
        return $this->db->count_all_results('Hits'); 
    } 
}       
        